package pc.util;

public class Executor {
	
	public static final int TEST_COUNT = 100;
	
	public static <T> void execute(String name, Task<T> task) {
		System.out.println("=============" + name + "=============");
		T in = null;
		long time = 0;
		long sum = 0;
		for ( int i = 0; i < TEST_COUNT; ++i ) {
			in = task.pre();
			time = System.currentTimeMillis();
			task.execute(in);
			sum += System.currentTimeMillis() - time;
		}
		sum /= TEST_COUNT;
		task.post(in);
		int sec = (int)(sum / 1000);
		int min = sec / 60; 
		sum %= 1000;
		boolean isValid = task.validate(in);
		System.out.println("Execution time was " + min + ":" + sec + ":" + sum);
		System.out.println("Task validation: " + isValid);
		System.out.println("==========================\n");
	}
	
}
